package com.wbao.dianniu.update;

import com.wbao.dianniu.data.AdvertListData;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yejianjun on 2018/6/14.
 */

public class ExchangeHisHelper {

    private static ExchangeHisHelper instance;
    private List<IExchangeHistListener> mListener = null;

    public static ExchangeHisHelper getInstance() {
        if (null == instance) {
            instance = new ExchangeHisHelper();
        }
        return instance;
    }

    private void ExchangeHisHelper() {
        mListener = new ArrayList<>();
    }

    public interface IExchangeHistListener {
        public void addOneExchange(AdvertListData data);

        public void removeOneExchange(int id);

        public void modifyOneExchange(int id, AdvertListData data);
    }

    public void addListener(IExchangeHistListener listenr) {
        if (null == mListener) {
            mListener = new ArrayList<>();
        }
        mListener.add(listenr);
    }

    public void removeListener(IExchangeHistListener listener) {
        if (null != mListener) {
            mListener.remove(listener);
        }
    }

    public void addOneExchange(AdvertListData data) {
        if (null != mListener) {
            for (int i = 0; i < mListener.size(); i++) {
                mListener.get(i).addOneExchange(data);
            }
        }
    }

    public void removeOneExchange(int id) {
        if (null != mListener) {
            for (int i = 0; i < mListener.size(); i++) {
                mListener.get(i).removeOneExchange(id);
            }
        }
    }

    public void modifyOneExchange(int id, AdvertListData data) {
        if (null != mListener) {
            for (int i = 0; i < mListener.size(); i++) {
                mListener.get(i).modifyOneExchange(id, data);
            }
        }
    }


}
